class Particle(object):
    #constructor method
    def __init__(self, mass, velocity):
        # assign attribute values of new object
        self.mass = mass
        self.velocity = velocity
    # method for calculating object momentum
    def momentum(self):
        return self.mass * self.velocity
    # a "magic" method defines object's string representation
    def __repr__(self):
        msg = "(m:%2.1f, v:%2.1f)" % (self.mass, self.velocity)
        return msg
    def __add__(self, other):
        if not isinstance(other, Particle):
            return NotImplemented
        mnew = self.mass + other.mass
        vnew = (self.momentum() + other.momentum())/mnew
        return Particle(mnew, vnew)        

a = Particle(3.2, 4.1)
b = Particle(8.6, 10.2)
print b, a
print a+b
print a.momentum()
print b.momentum()
print (a+b).momentum()


